<template>
	<view class="container">
		<scroll-view scroll-y="true" class="scroll">
			<view class="scroll-center" v-for="(item,index) in serviceData" :key="index">
				<view class="device">
					<view class="device_top">
						<view class="device_left">
							<text class="devices">设备安装</text>
							<text>服务工程师：{{item.serviceUserName}}</text>
							<text>服务时间：2023-04-27 14:25</text>
						</view>
						<view class="device_right">
							<image src="/static/image/shop/1.png" mode=""></image>
						</view>
					</view>
					<textarea @blur="bindTextAreaBlur" placeholder-class="placeholder"
						placeholder="请对本次服务进行评价"></textarea>
					<view class="evaluate">
						<view class="evaluate_all">
							综合评价：
						</view>
						<view class="all_c" v-for="(eval, index) in evaluations" :key="index"
							@click="selectEvaluation(eval)">
							<image
								:src="selectedEvaluation === eval ? '/static/image/shop/17-2.png' : '/static/image/shop/17-1.png'"
								alt="Star">
								<span
									:style="{ color: selectedEvaluation === eval ? '#42a3aa' : '#cfcfcf' }">{{ eval }}</span>
						</view>
					</view>
				</view>
				<view class="evaluatebtn">
					<button class="btn" @click="evaluate">提交评价</button>
				</view>
			</view>
		</scroll-view>


	</view>
</template>

<script>
	import $http from "@/ajax/http.js"
	export default {
		data() {
			return {
				token: wx.getStorageSync('token'),
				selectedEvaluation: null,
				evaluations: ['差评', '中评', '好评'],
				serviceComment: '',
				serviceData: ''
			}
		},
		onLoad(options) {
			this.getServiceComments();
		},
		methods: {
			selectEvaluation(evaluation) {
				this.selectedEvaluation = evaluation; // 设置选中的评价  
			},
			getServiceComments() {
				$http.request({
					header: {
						Authorization: this.token,
					},
					url: '/store/my/getServiceComments',
					method: "GET",
				}).then((res) => {
					console.log(res, "获取服务评价单");
					this.serviceData = res
				})
			},

			bindTextAreaBlur(e) {
				this.serviceComment = e.detail.value
				console.log(e.detail.value, "eeeeeeeeee");
			},

			evaluate() {
				let serviceCommentValue = 1; // 默认为1
				if (this.selectedEvaluation === '中评') {
					serviceCommentValue = 2;
				} else if (this.selectedEvaluation === '好评') {
					serviceCommentValue = 3;
				}
				$http.request({
					header: {
						Authorization: this.token,
					},
					url: '/store/my/serviceComments',
					data: {
						levelComment: serviceCommentValue,
						serviceComment: this.serviceComment,
					},
					method: "POST",
				}).then((res) => {
					wx.showModal({
						title: '提示',
						content: '您的评价已上传，十分感谢！',
						showCancel: false
					})
				})
			}

		}
	}
</script>

<style scoped lang="scss">
	@import '@/common/sass/all/all.scss';

	.scroll {
		height: calc(100vh);

		.scroll-center {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
		}
	}

	.device {
		width: 683rpx;
		background: #ffffff;
		border-radius: 25rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 30rpx;

		.device_top {
			width: 583rpx;
			display: flex;
			justify-content: space-between;
			flex-direction: row;

			.device_left {
				display: flex;
				flex-direction: column;
				font-size: 22rpx;
				font-weight: 400;
				color: #4C4948;
				line-height: 32rpx;
				margin-top: 50rpx;

				.devices {
					font-size: 30rpx;
					font-weight: bold;
					color: #00828C;
					margin-bottom: 20rpx;
				}
			}

			.device_right {
				margin-top: 30rpx;

				image {
					width: 127rpx;
					height: 134rpx;
				}
			}
		}

		textarea {
			margin-top: 10rpx;
			width: 583rpx;
			height: 210rpx;
			border: 1rpx solid #eaeaea;
			border-radius: 15rpx;
		}

		.placeholder {
			font-size: 22rpx;
			color: red;
		}

		.evaluate {
			width: 583rpx;
			line-height: 80rpx;
			display: flex;
			flex-direction: row;

			.evaluate_all {
				font-size: 22rpx;
				font-weight: 400;
				color: #7D7D7D;
			}

			.all_c {
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-left: 25rpx;

				span {
					font-size: 22rpx;
					margin-left: 10rpx;
				}

				image {
					width: 25rpx;
					height: 25rpx;
				}

				text {
					font-size: 22rpx;
					font-weight: 400;
					color: #00828C;
					line-height: 28rpx;
					margin-left: 6rpx;
				}
			}
		}
	}

	.evaluatebtn {
		margin-bottom: 20rpx;

		.btn {
			width: 676rpx;
			height: 90rpx;
			line-height: 90rpx;
			background: linear-gradient(to right, rgba(19, 182, 163, 1), rgba(0, 130, 140, 1));
			box-shadow: 5rpx 5rpx 5rpx #085d63;
			border-radius: 15rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: #FFFFFF;
		}
	}
</style>